]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Use LC_TIME locale for strftime format string translations
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 16 Oct 2014 12:38:13 +0000 (14:38 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 16 Oct 2014 21:41:51 +0000 (23:41 +0200)
We commonly mark strftime format strings for translation to account
for date/time representations without an existing strftime shortcut
("Yesterday %H%p"). As those translations are looked up according to
the locale defined by LC_MESSAGES, while the conversion characters
themselves are resolved according to LC_TIME, the result can be
rather odd when mixing locales ("Den 27. January"). The correct
solution would be to install translations for format strings in
the LC_TIME catalogue and look them up with dcgettext(), but we
don't have the infrastructure to do that easily. Work around this
by adding a helper method that looks up a string in LC_MESSAGES
using the locale defined by LC_TIME and use that to translate
format strings, which has the same result.

https://bugzilla.gnome.org/show_bug.cgi?id=738640

js/ui/calendar.js
js/ui/components/telepathyClient.js
js/ui/dateMenu.js
js/ui/screenShield.js
src/shell-util.c
src/shell-util.h

index 77f8b648d39ee63765c8a2fd96718c0fdd5c1aa9..db6cb2c3fde17077d57df522b5c6bbf69faebf2d 100644 (file)
@@ -16,6 +16,7 @@ const SHOW_WEEKDATE_KEY = 'show-weekdate';
 
 // alias to prevent xgettext from picking up strings translated in GTK+
 const gtk30_ = Gettext_gtk30.gettext;
+const NC_ = function(context, str) { return str; };
 
 // in org.gnome.desktop.interface
 const CLOCK_FORMAT_KEY        = 'clock-format';
@@ -792,14 +793,17 @@ const EventsList = new Lang.Class({
         let dayBegin = _getBeginningOfDay(day);
         let dayEnd = _getEndOfDay(day);
 
-        let dayString;
+        let dayFormat;
         let now = new Date();
         if (_sameYear(day, now))
             /* Translators: Shown on calendar heading when selected day occurs on current year */
-            dayString = day.toLocaleFormat(C_("calendar heading", "%A, %B %d"));
+            dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
+                                                             "%A, %B %d"));
         else
             /* Translators: Shown on calendar heading when selected day occurs on different year */
-            dayString = day.toLocaleFormat(C_("calendar heading", "%A, %B %d, %Y"));
+            dayFormat = Shell.util_translate_time_string(NC_("calendar heading",
+                                                             "%A, %B %d, %Y"));
+        let dayString = day.toLocaleFormat(dayFormat);
         this._addPeriod(dayString, 0, dayBegin, dayEnd, false, true);
     },
 
index 0d5fc0ea1cc25ef35f1a8c17871c7bbdd6c6d700..fc535ebde3e63656e23403471bb17ec4a46dfb30 100644 (file)
@@ -36,6 +36,8 @@ const NotificationDirection = {
     RECEIVED: 'chat-received'
 };
 
+const N_ = function(s) { return s; };
+
 function makeMessageFromTpMessage(tpMessage, direction) {
     let [text, flags] = tpMessage.to_text();
 
@@ -950,70 +952,70 @@ const ChatNotification = new Lang.Class({
             // Show only the time if date is on today
             if(daysAgo < 1){
                 /* Translators: Time in 24h format */
-                format = _("%H\u2236%M");
+                format = N_("%H\u2236%M");
             }
             // Show the word "Yesterday" and time if date is on yesterday
             else if(daysAgo <2){
                 /* Translators: this is the word "Yesterday" followed by a
                  time string in 24h format. i.e. "Yesterday, 14:30" */
                 // xgettext:no-c-format
-                format = _("Yesterday, %H\u2236%M");
+                format = N_("Yesterday, %H\u2236%M");
             }
             // Show a week day and time if date is in the last week
             else if (daysAgo < 7) {
                 /* Translators: this is the week day name followed by a time
                  string in 24h format. i.e. "Monday, 14:30" */
                 // xgettext:no-c-format
-                format = _("%A, %H\u2236%M");
+                format = N_("%A, %H\u2236%M");
 
             } else if (date.getYear() == now.getYear()) {
                 /* Translators: this is the month name and day number
                  followed by a time string in 24h format.
                  i.e. "May 25, 14:30" */
                 // xgettext:no-c-format
-                format = _("%B %d, %H\u2236%M");
+                format = N_("%B %d, %H\u2236%M");
             } else {
                 /* Translators: this is the month name, day number, year
                  number followed by a time string in 24h format.
                  i.e. "May 25 2012, 14:30" */
                 // xgettext:no-c-format
-                format = _("%B %d %Y, %H\u2236%M");
+                format = N_("%B %d %Y, %H\u2236%M");
             }
         } else {
             // Show only the time if date is on today
             if(daysAgo < 1){
                 /* Translators: Time in 24h format */
-                format = _("%l\u2236%M %p");
+                format = N_("%l\u2236%M %p");
             }
             // Show the word "Yesterday" and time if date is on yesterday
             else if(daysAgo <2){
                 /* Translators: this is the word "Yesterday" followed by a
                  time string in 12h format. i.e. "Yesterday, 2:30 pm" */
                 // xgettext:no-c-format
-                format = _("Yesterday, %l\u2236%M %p");
+                format = N_("Yesterday, %l\u2236%M %p");
             }
             // Show a week day and time if date is in the last week
             else if (daysAgo < 7) {
                 /* Translators: this is the week day name followed by a time
                  string in 12h format. i.e. "Monday, 2:30 pm" */
                 // xgettext:no-c-format
-                format = _("%A, %l\u2236%M %p");
+                format = N_("%A, %l\u2236%M %p");
 
             } else if (date.getYear() == now.getYear()) {
                 /* Translators: this is the month name and day number
                  followed by a time string in 12h format.
                  i.e. "May 25, 2:30 pm" */
                 // xgettext:no-c-format
-                format = _("%B %d, %l\u2236%M %p");
+                format = N_("%B %d, %l\u2236%M %p");
             } else {
                 /* Translators: this is the month name, day number, year
                  number followed by a time string in 12h format.
                  i.e. "May 25 2012, 2:30 pm"*/
                 // xgettext:no-c-format
-                format = _("%B %d %Y, %l\u2236%M %p");
+                format = N_("%B %d %Y, %l\u2236%M %p");
             }
         }
-        return date.toLocaleFormat(format);
+        return date.toLocaleFormat(Shell.util_translate_time_string(format));
     },
 
     appendTimestamp: function() {
index db8f2a5563b6c023fac812814ba9f448c65dda54..79787eb8ebb8bc97b44cf4776cd8bda424b79374 100644 (file)
@@ -129,7 +129,7 @@ const DateMenuButton = new Lang.Class({
                 /* Translators: This is the date format to use when the calendar popup is
                  * shown - it is shown just below the time in the shell (e.g. "Tue 9:29 AM").
                  */
-                let dateFormat = _("%A %B %e, %Y");
+                let dateFormat = Shell.util_translate_time_string ("%A %B %e, %Y");
                 this._date.set_label(now.toLocaleFormat(dateFormat));
             }
         }));
index 32ef1ca9e1717b6144c449d4181b0e08014ecc6c..55412155bcebb480f4b0c1fbd1f0f08925265969 100644 (file)
@@ -85,7 +85,8 @@ const Clock = new Lang.Class({
         let date = new Date();
         /* Translators: This is a time format for a date in
            long format */
-        this._date.text = date.toLocaleFormat(_("%A, %B %d"));
+        let dateFormat = Shell.util_translate_time_string("%A, %B %d");
+        this._date.text = date.toLocaleFormat(dateFormat);
     },
 
     destroy: function() {
index 5ae4fdb3c454e0f0851d0a8537db52d5ec611090..c3936c1a8060a9d3f17d1134e37460b1117bb594 100644 (file)
@@ -12,6 +12,7 @@
 #include <gdk/gdkx.h>
 #include <X11/extensions/XTest.h>
 
+#include <locale.h>
 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
 #include <langinfo.h>
 #endif
@@ -208,6 +209,32 @@ shell_util_get_week_start ()
   return week_start;
 }
 
+/**
+ * shell_util_translate_time_string:
+ * @str: String to translate
+ *
+ * Translate @str according to the locale defined by LC_TIME; unlike
+ * dcgettext(), the translations is still taken from the LC_MESSAGES
+ * catalogue and not the LC_TIME one.
+ *
+ * Returns: the translated string
+ */
+const char *
+shell_util_translate_time_string (const char *str)
+{
+  const char *locale = g_getenv ("LC_TIME");
+  const char *res;
+
+  if (locale)
+    setlocale (LC_MESSAGES, locale);
+
+  res = gettext (str);
+
+  setlocale (LC_MESSAGES, "");
+
+  return res;
+}
+
 /**
  * shell_write_string_to_stream:
  * @stream: a #GOutputStream
index d7ab4fdcf6f79aafe193bfc33dbd2fc614d1878d..153278eb2194b0a56fa2ad736e551394da08e4a0 100644 (file)
@@ -21,6 +21,7 @@ int      shell_util_get_week_start             (void);
 
 char    *shell_util_format_date                (const char       *format,
                                                 gint64            time_ms);
+const char *shell_util_translate_time_string   (const char *str);
 
 gboolean shell_write_string_to_stream          (GOutputStream    *stream,
                                                 const char       *str,